package com.antkit.mark.ak.wedigt;

import android.content.Context;
import android.graphics.*;
import android.util.AttributeSet;
import android.view.View;

/**
 * @author Mark
 * @Date on 2019/3/5
 **/
public class SanDTestView extends View {
    public SanDTestView(Context context) {
        super(context);
    }

    public SanDTestView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SanDTestView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public SanDTestView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }


    private Bitmap bitmap;

    private Paint mPaint;
    public void setBitmap(Bitmap bitmap) {
        this.bitmap = bitmap;
        mPaint = new Paint();
        mPaint.setColor(Color.parseColor("#88000000"));
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (bitmap!=null){
            //Camera
            Camera camera = new Camera();
            canvas.save();
            canvas.translate(bitmap.getWidth()/2+200,bitmap.getHeight()/2+20);

            camera.save();
            camera.rotateX(30); // 旋转 Camera 的三维空间
            camera.applyToCanvas(canvas); // 把旋转投影到 Canvas
            camera.restore();

            canvas.translate(-bitmap.getWidth()/2-200,-bitmap.getHeight()/2-20);

            canvas.drawBitmap(bitmap, 200, 20, mPaint);
            canvas.restore();
        }


    }
}
